package component.security.encrypt;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.PrivateKey;


import component.security.util.Constant;
import component.security.util.FileUtil;


/**
 * 获取密文运行类
 *
 */
public class CryptoRunner {
	
	/**
	 * 将密文写入文件
	 * @preserve
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception{		
		crypto();		
	}
	
	/**
	 * 加密文件
	 * @throws Exception
	 */
	private static void crypto()throws Exception{
		System.out.println("开始加密.........\n");
		
		//获取明文、密文(Lience)和私钥文件
		String lienceFile = FileUtil.getFileDir(Constant.LIENCE_FILE) ;;
		String lienceCryptoFile = FileUtil.getFileDir(Constant.LIENCE_CRYPTO_FILE);
		String lienceOrignFile = FileUtil.getFileDir(Constant.LIENCE_OBJ_FILE);
		String priKeyFile = FileUtil.getFileDir(Constant.PRIKEY_FILE);
	
        //获取私钥
		PrivateKey privateKey = Util.getPrivateKeyFromFile(priKeyFile);
		
		//用私钥对明文(Lience)加密
		new Crypto().encrypt(privateKey, lienceFile,lienceOrignFile,lienceCryptoFile);  
		
		System.out.println("加密成功！\n");
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		br.readLine();
	    
	}
}
